from PySide6.QtWidgets import QPushButton
from PySide6.QtCore import Qt, QSize, QEvent

class BaseButton(QPushButton):
    """基础按钮类，提供共享的基本功能"""
    
    def __init__(self, text="", parent=None):
        super().__init__(text, parent)
        self.setMinimumHeight(36)  # 增加高度
        self.setCursor(Qt.PointingHandCursor)
        self.setFocusPolicy(Qt.StrongFocus)
        
    def enterEvent(self, event):
        """鼠标进入事件处理"""
        self.animate_hover(True)
        super().enterEvent(event)
        
    def leaveEvent(self, event):
        """鼠标离开事件处理"""
        self.animate_hover(False)
        super().leaveEvent(event)
        
    def animate_hover(self, hovering):
        """处理悬停动画效果"""
        # 在子类中实现具体效果
        pass
        
class PrimaryButton(BaseButton):
    """主要操作按钮"""
    
    def __init__(self, text="", parent=None):
        super().__init__(text, parent)
        self.setObjectName("primaryButton")
        self.setStyleSheet("""
            #primaryButton {
                background-color: qlineargradient(x1:0, y1:0, x2:0, y2:1,
                                   stop:0 #2196F3, stop:1 #1976D2);
                color: white;
                border: none;
                border-radius: 8px;
                padding: 10px 18px;
                font-weight: bold;
            }
            #primaryButton:hover {
                background-color: qlineargradient(x1:0, y1:0, x2:0, y2:1,
                                   stop:0 #1E88E5, stop:1 #1565C0);
            }
            #primaryButton:pressed {
                background-color: qlineargradient(x1:0, y1:0, x2:0, y2:1,
                                   stop:0 #1565C0, stop:1 #0D47A1);
                padding: 12px 18px 8px 18px;
            }
            #primaryButton:disabled {
                background-color: #BBDEFB;
                color: #90A4AE;
            }
        """)
        
class DangerButton(BaseButton):
    """危险操作按钮"""
    
    def __init__(self, text="", parent=None):
        super().__init__(text, parent)
        self.setObjectName("dangerButton")
        self.setStyleSheet("""
            #dangerButton {
                background-color: qlineargradient(x1:0, y1:0, x2:0, y2:1,
                                   stop:0 #F44336, stop:1 #D32F2F);
                color: white;
                border: none;
                border-radius: 8px;
                padding: 10px 18px;
                font-weight: bold;
            }
            #dangerButton:hover {
                background-color: qlineargradient(x1:0, y1:0, x2:0, y2:1,
                                   stop:0 #E53935, stop:1 #C62828);
            }
            #dangerButton:pressed {
                background-color: qlineargradient(x1:0, y1:0, x2:0, y2:1,
                                   stop:0 #D32F2F, stop:1 #B71C1C);
                padding: 12px 18px 8px 18px;
            }
            #dangerButton:disabled {
                background-color: #FFCDD2;
                color: #90A4AE;
            }
        """)
        
class WarningButton(BaseButton):
    """警告操作按钮"""
    
    def __init__(self, text="", parent=None):
        super().__init__(text, parent)
        self.setObjectName("warningButton")
        self.setStyleSheet("""
            #warningButton {
                background-color: qlineargradient(x1:0, y1:0, x2:0, y2:1,
                                   stop:0 #FF9800, stop:1 #F57C00);
                color: white;
                border: none;
                border-radius: 8px;
                padding: 10px 18px;
                font-weight: bold;
            }
            #warningButton:hover {
                background-color: qlineargradient(x1:0, y1:0, x2:0, y2:1,
                                   stop:0 #FB8C00, stop:1 #EF6C00);
            }
            #warningButton:pressed {
                background-color: qlineargradient(x1:0, y1:0, x2:0, y2:1,
                                   stop:0 #F57C00, stop:1 #E65100);
                padding: 12px 18px 8px 18px;
            }
            #warningButton:disabled {
                background-color: #FFE0B2;
                color: #90A4AE;
            }
        """)
        
class SuccessButton(BaseButton):
    """成功操作按钮"""
    
    def __init__(self, text="", parent=None):
        super().__init__(text, parent)
        self.setObjectName("successButton")
        self.setStyleSheet("""
            #successButton {
                background-color: qlineargradient(x1:0, y1:0, x2:0, y2:1,
                                   stop:0 #4CAF50, stop:1 #388E3C);
                color: white;
                border: none;
                border-radius: 8px;
                padding: 10px 18px;
                font-weight: bold;
            }
            #successButton:hover {
                background-color: qlineargradient(x1:0, y1:0, x2:0, y2:1,
                                   stop:0 #43A047, stop:1 #2E7D32);
            }
            #successButton:pressed {
                background-color: qlineargradient(x1:0, y1:0, x2:0, y2:1,
                                   stop:0 #388E3C, stop:1 #1B5E20);
                padding: 12px 18px 8px 18px;
            }
            #successButton:disabled {
                background-color: #C8E6C9;
                color: #90A4AE;
            }
        """)
        
class InfoButton(BaseButton):
    """信息操作按钮"""
    
    def __init__(self, text="", parent=None):
        super().__init__(text, parent)
        self.setObjectName("infoButton")
        self.setStyleSheet("""
            #infoButton {
                background-color: qlineargradient(x1:0, y1:0, x2:0, y2:1,
                                  stop:0 #00BCD4, stop:1 #0097A7);
                color: white;
                border: none;
                border-radius: 8px;
                padding: 10px 18px;
                font-weight: bold;
            }
            #infoButton:hover {
                background-color: qlineargradient(x1:0, y1:0, x2:0, y2:1,
                                  stop:0 #00ACC1, stop:1 #00838F);
            }
            #infoButton:pressed {
                background-color: qlineargradient(x1:0, y1:0, x2:0, y2:1,
                                  stop:0 #0097A7, stop:1 #006064);
                padding: 12px 18px 8px 18px;
            }
            #infoButton:disabled {
                background-color: #B2EBF2;
                color: #90A4AE;
            }
        """) 